<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
	<title>post</title>
</head>
<body>

<div class="app">

    <form>

        user： <input type="text" id="user"><br>

        password： <input type="password" id="password">

        <button>提交</button>

    </form>
    
</div>

<script type="text/javascript">

/* post注意

    1. xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    2. 参数的拼接 var data = 'user='+user+'&password='+password;
*/


var btn = document.getElementsByTagName('button')[0];

btn.onclick = function() {
    var user = document.getElementById('user').value;

    var password = document.getElementById('password').value;

    var data = 'user='+user+'&password='+password;

    if (window.XMLHttpRequest) {
        var xhr = new XMLHttpRequest();
    } else {
        var xhr = new ActiveXObject('Micosoft');
    }

    xhr.open('POST', 'http://php.com/007.php', true);

    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    xhr.send(data);

    xhr.onreadystatechange = function() {
        if (xhr.readyState == 4) {
            if (xhr.status == 200) {
                alert(xhr.responseText);
            }
        }
    }

}



</script>
</body>
</html>